<?php

namespace Home\Controller;

use Think\Controller;
use Home\Biz\AdminBiz;
use Home\Biz\OrderBiz;
use Home\Biz\StringBiz;

class OrderController extends AuditBaseController {
	
	public function orderlist($type = 1) {
		$promoter_id = $this->promoter_en['promoter_id'];
		
		$size = C('OrderConfig.order_list_size');
		$lst_promoter_order_en = OrderBiz::getOrderList($promoter_id, $type, 1, $size);
		
		$this->assign('lst_order_en', $lst_promoter_order_en);
		$this->assign('type', $type);
		$this->assign('page_name', '订单列表');
		$this->display ( "order/order_list" );
	}
	
	public function logisticsDetail() {
		$logistics_no = I('logistics_no');
		
		$this->assign('page_name', '物流追踪');
		$this->assign('logistics_no', $logistics_no);
		
		$url  = "http://www.rrs.com/wl/ajax/querymsginfofromles?kscx_id=$logistics_no";
		$json_str = file_get_contents($url);
		$result_en = json_decode($json_str, true);
		
		$lst_logistics_en = $result_en['result']['OUTPUT'];
		
		
		$this->assign('lst_logistics_en', $lst_logistics_en);
		
		
		$this->display ( "order/logistics_detail" );
	}
	
	
	public function orderdetail() {
		$this->assign('page_name', '订单详情');
		
		$order_id = I('order_id');
		
		$promoter_order_en = M('promoterOrder')->where("order_id='%s'",$order_id)->find();
		$promoter_order_en['order_status_text'] = StringBiz::getPromoterOrderStatusText($promoter_order_en['order_status']);
		$promoter_order_en['order_revenue_status_text'] = StringBiz::getPromoterOrderRevenueStatusText($promoter_order_en['order_revenue_status']);
		$order_en = M('orderInfo', '', 'DB_trade')->where("order_id='%s'",$order_id)->find();
		$lst_order_detail_en = M('orderDetail', '', 'DB_trade')->where("order_id='%s'",$order_id)->select();

		foreach($lst_order_detail_en as $index => $order_detail_en){
			$lst_order_detail_en[$index]['image'] = $lst_order_detail_en[$index]['image'];
			
			$order_en['logistics_company'] = $order_detail_en['logistics_company'];
			$order_en['logistics_no'] = $order_detail_en['logistics_no'];
		}
		
		
		//是否可以支付
		$can_payment = 0;
		//是否可以取消
		$can_cancel = 0;
	
		
		if(in_array($order_en['order_status'], C('OrderConfig.can_payment_order_status_list'))
				&& in_array($order_en['payment_status'], C('OrderConfig.can_payment_payment_status_list'))){
					$can_payment = 1;
		}
		
		if(in_array($order_en['order_status'], C('OrderConfig.can_cancel_order_status_list'))
				&& in_array($order_en['payment_status'], C('OrderConfig.can_cancel_payment_status_list'))){
					$can_cancel = 1;
		}
		$this->assign('can_payment', $can_payment);
		$this->assign('can_cancel', $can_cancel);
		

		$this->assign('promoter_order_en', $promoter_order_en);
		$this->assign('order_en', $order_en);
		$this->assign('lst_order_detail_en', $lst_order_detail_en);
		
		$this->display ( "order/order_detail" );
	}
}